package com.dayaokeji.rhythmschoolstudent.client.home.helper


import android.os.Bundle
import android.support.v4.app.Fragment
import android.text.Html
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup

import com.dayaokeji.rhythmschoolstudent.R
import com.dayaokeji.rhythmschoolstudent.client.common.base.ActivityTemplateMethod
import com.dayaokeji.rhythmschoolstudent.utils.PermissionUtil
import kotlinx.android.synthetic.main.fragment_helper_step_one.*


/**
 * @author feiwo
 *
 * course sign failed helper step 2
 *
 */
class HelperStepTwoFragment : Fragment(), ActivityTemplateMethod {


    companion object {
        fun newInstance() = HelperStepTwoFragment()
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?,
                              savedInstanceState: Bundle?): View? {
        return inflater.inflate(R.layout.fragment_helper_step_one, container, false)
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        init()
        setOnListener()
    }

    override fun setupView() {
        btnLeft.text = "已授权"
        btnRight.text = "去授权"
    }

    override fun setupViewData() {
        val helperStr = "2.签到功能需要相关权限，请确认<font color='#6FB7FF'><b>【位置信息】</b></font>、<font color='#6FB7FF'><b>【WIFI】</b></font>、<font color='#6FB7FF'><b>【GPS】</b></font>权限是否打开？<br/><br/>以小米手机为例：";

        tvHelperTips.text = Html.fromHtml(helperStr)

        ivHelperImg.setImageResource(R.mipmap.img_course_sign_failed_step_2)
    }

    private fun setOnListener() {
        btnLeft.setOnClickListener {
            activity?.let {
                if (it is CourseSignFailedHelperActivity) {
                    it.nextPage()
                }
            }
        }

        btnRight.setOnClickListener {
            activity?.let {
                PermissionUtil.startSetting(it)
            }
        }
    }
}
